// pages/usercenter/setup/index.js
let app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        colors: null,
        sizes: null,
        warnVal: 100,
        qtyStepper: 0,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            spinShow: true,
            queryParam: {},
        });
        this.queryData()
    },

    inputChange(e) {
        console.log(e)
        let id = e.currentTarget.id
        this.setData({
            [id]: e.detail
        })
    },

    onChange(event) {
        this.setData({
            sizes: event.detail,
        });
    },

    queryData: function () {
        let _this = this
        app.formGet('/app/boss/setup/get', this.data.queryParam).then(res => {
            _this.setData({
                spinShow: false
            });
            wx.stopPullDownRefresh()
            if (res.code === 0) {
                if (res.data) {
                    _this.setData({
                        colors: res.data.colors,
                        sizes: res.data.sizes,
                        warnVal: res.data.warnVal,
                        qtyStepper: res.data.qtyStepper
                    });
                }
            } else {
                app.message(res.message, 'error')
            }
        }).catch(e => {
            _this.setData({
                spinShow: false
            });
            app.message(e, 'error')
        })
    },
    handleSetup() {
        let _this = this
        let data = {}
        data.colors = this.data.colors
        data.sizes = this.data.sizes
        data.warnVal = this.data.warnVal
        data.qtyStepper = this.data.qtyStepper
        app.formPost('/app/boss/setup/edit', data).then(res => {
            _this.setData({
                spinShow: false
            });
            wx.stopPullDownRefresh()
            if (res.code === 0) {
                app.message(res.message, 'success')
                // 修改只有初始化用户信息
                app.initUserData()
                setTimeout(function () {
                    wx.navigateBack()
                }, 2000)
            } else {
                app.message(res.message, 'error')
            }
        }).catch(e => {
            _this.setData({
                spinShow: false
            });
            app.message(e, 'error')
        })
    }

})